# -*- coding: utf-8 -*-
# @Time    :2022/2/16 21:04
# @AUTHOR  :MORAN
# @Email   :moran@maqu.com
# @File    :serializers.py
# @Software:PyCharm
from rest_framework import serializers
from rest_framework.serializers import ModelSerializer
from .models import Label, Topic


class LabelSerializer(ModelSerializer):
    class Meta:
        model = Label
        fields = '__all__'


class TopicSerializer(ModelSerializer):
    label_name = serializers.CharField(source='label.name', read_only=True)
    user_name = serializers.CharField(source='user.first_name', read_only=True)

    class Meta:
        model = Topic
        exclude = ['is_delete']


class TopicStudentSerializer(ModelSerializer):
    label_name = serializers.CharField(source='label.name', read_only=True)
    user_name = serializers.CharField(source='user.first_name', read_only=True)

    class Meta:
        model = Topic
        exclude = ['is_delete', 'label', 'user']


class TopicNoAnswerSerializer(ModelSerializer):
    label_name = serializers.CharField(source='label.name', read_only=True)
    user_name = serializers.CharField(source='user.first_name', read_only=True)

    class Meta:
        model = Topic
        exclude = ['is_delete', 'answer']


class LabelTopicSerializer(ModelSerializer):
    class Meta:
        model = Label
        fields = '__all__'

    topic_set = TopicNoAnswerSerializer(many=True, required=False, read_only=True)
